<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Forum/classes/PhpFox_ComponentMoveTopic.class.php, $Author:  $ */



/** Move selected topic
 * 
 * @package module.forum
 * @version $Id: PhpFox_ComponentMoveTopic.class.php 391 2008-03-04 19:52:13Z phpfoxsv $
 *   
 */
class PhpFox_Mod_Forum_ComponentMoveTopic extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
	    
	    $oReq = &App::getRequest();
	    /* @var $oReq Request */
	    $iTopicId = $oReq->getInt('id');
	    
	    $oSrvSec = &App::getModuleService('Account', 'Security');
	    
	    //check user is admin and forum ID is defined
	    if ( !($oSrvSec->isStaff() && $iTopicId) )
	    {
	        App::gotoUrl('public.forum');
	    }
	    
	    $oSrvForum = &App::getModuleService('Forum', 'Forum');
	    /* @var $oSrvForum PhpFox_Mod_Forum_ServiceForum */
	    
	    $oTopic = $this->_oModule->getItem('ForumTopic');
        if(!$oTopic->load($iTopicId))
        {
	        App::gotoUrl('public.forum');
        }
        switch($oReq->getAction())
        {
            case 'forum_move_topic':

                if ($oSrvForum->moveTopic($oTopic, $oReq->getInt('forum_id')))
                {
                    App::gotoUrl('public.forum.posts', array('id'=>$iTopicId));
                }
                else
                {
                    $this->addErrors($oSrvForum->getErrors());
                }
                break;
        }
        

        $aForums = $oSrvForum->getForumHash();
        unset($aForums[$oTopic->aData['type']]); //unset current forum
        
		$oTpl = &$this->_oModule->getTemplate();
		$oTpl->assign(array(
            'aForums' => $aForums,
		));
		$srcHtml = $oTpl->fetch('MoveTopic.html');
		return $srcHtml;
	}

}
?>